<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%
	   String managerId = request.getParameter("managerId");
       String classId = request.getParameter("classId");
       int t=0;
       String managerName = new String(request.getParameter("managerName").getBytes("ISO8859-1"),"UTF-8");
       String managerSex = new String(request.getParameter("managerSex").getBytes("ISO-8859-1"),"UTF-8");
       String managerPwd = request.getParameter("managerPwd");
       try{
    	   Class.forName("com.mysql.jdbc.Driver").newInstance();
    	   Connection con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/classfee", "root", "1234");
    	   Statement stmt = con.createStatement();
    		ResultSet srt = stmt.executeQuery("SELECT managerId FROM  tb_manager where managerId='"+managerId+"'");
    		while(srt.next())
    		{
    			if(srt.getString("managerId").equals(managerId))
    			{
    				t=1;
    				break;
    			}
    		}
    		if(t==1)
    		   out.println("<script>alert('该工号已注册过!');window.location='manageradd1.jsp'</script>");
    		else
    		{
    	       stmt.executeUpdate("insert into tb_manager(managerId,classId,managerName,managerSex,managerPwd) values('"+managerId+"','" +classId+"','"+managerName+"','"+managerSex+"','"+managerPwd+"')");
    	       out.println("<script>alert('注册成功!');window.location='../managerLogin.html'</script>");
    		}
    		srt.close();
    		stmt.close();
 	       	con.close();
         }
      catch(Exception ex)
      { 
    	   out.println("<script>alert('注册失败!');");
    	   out.println(ex.getMessage());
      }
	       
%>
